package com.zh.zhbootcommon.entity.user;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zh.zhbootcommon.domain.DBaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 权限/菜单信息表
 * </p>
 *
 * @author JueDream
 * @since 2021-08-04
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("zh_permission")
@ApiModel(value="ZhPermission对象", description="权限/菜单信息表")
public class Permission extends DBaseEntity implements Serializable {

    @ApiModelProperty(value = "权限编号")
    @TableId(value = "p_id", type = IdType.AUTO)
    private Integer pId;

    @ApiModelProperty(value = "权限名称")
    @TableField("p_name")
    private String pName;

    @ApiModelProperty(value = "权限类型 menu button")
    @TableField("p_type")
    private String pType;

    @ApiModelProperty(value = "权限路径")
    @TableField("p_url")
    private String pUrl;

    @ApiModelProperty(value = "权限规则 user:add")
    @TableField("p_rule")
    private String pRule;

    @ApiModelProperty(value = "权限父节点")
    @TableField("p_parent_id")
    private Integer pParentId;

    @ApiModelProperty(value = "权限父节点名称")
    @TableField(exist = false)
    public String pParentName;

    @ApiModelProperty(value = "权限父节点(多个-直到顶点)")
    @TableField("p_parent_ids")
    private String pParentIds;

    @ApiModelProperty(value = "权限是否可用 0-true 1-false")
    @TableField("p_available")
    private Integer pAvailable;

    @ApiModelProperty(value = "权限请求类型 POST/GET/DELETE")
    @TableField("p_req_type")
    private String pReqType;

    @ApiModelProperty(value = "权限备注")
    @TableField("p_remark")
    private String pRemark;

    @ApiModelProperty(value = "菜单权限子集")
    @TableField(exist = false)
    private List<Permission> children = new ArrayList<>();

    public Permission(){}

    private static final long serialVersionUID = 1L;

    public Permission(Integer pId, String pName, String pType, String pUrl, String pRule, String pReqType, Integer pParentId, String pParentIds, Integer pAvailable, String pRemark, List<Permission> children) {
        this.pId = pId;
        this.pName = pName;
        this.pType = pType;
        this.pUrl = pUrl;
        this.pRule = pRule;
        this.pReqType = pReqType;
        this.pParentId = pParentId;
        this.pParentIds = pParentIds;
        this.pAvailable = pAvailable;
        this.pRemark = pRemark;
        this.children = children;
    }
}